Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gas_price_service): initialize v1 metadata #2288

Merged
merged 29 commits into from
Oct 30, 2024

Conversation

rymnc
Copy link
Member

@rymnc rymnc commented Oct 4, 2024

Note

This is PR 1/n in introducing GasPriceServiceV1 which links to v1 of the gas-price-algorithm. This PR is mainly used to start the discussion around v1 metadata and the fields we need.

Linked Issues/PRs

fixes #2286

Description

  • Specifies a V1Metadata that will be stored along V0Metadata wrapped within the UpdaterMetadata struct.
  • We use fallible conversions between the two, v0 => v1 should be possible
  • Constructor for AlgorithmUpdaterV1 from V1Metadata

Bonus:

  • Also fixed the tests that were testing initialize_algorithm to test the UninitializedTask instead--a public interface.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@rymnc rymnc self-assigned this Oct 4, 2024
Comment on lines 8 to 53
pub struct V1Metadata {
// Execution
/// The gas price (scaled by the `gas_price_factor`) to cover the execution of the next block
pub new_scaled_exec_price: u64,
/// The lowest the algorithm allows the exec gas price to go
pub min_exec_gas_price: u64,
/// The Percentage the execution gas price will change in a single block, either increase or decrease
/// based on the fullness of the last L2 block. Using `u16` because it can go above 100% and
/// possibly over 255%
pub exec_gas_price_change_percent: u16,
/// The height of the next L2 block
pub l2_block_height: u32,
/// The threshold of gas usage above and below which the gas price will increase or decrease
/// This is a percentage of the total capacity of the L2 block
pub l2_block_fullness_threshold_percent: ClampedPercentage,
// DA
/// The gas price (scaled by the `gas_price_factor`) to cover the DA commitment of the next block
pub new_scaled_da_gas_price: u64,

/// Scale factor for the gas price.
pub gas_price_factor: NonZeroU64,
/// The lowest the algorithm allows the da gas price to go
pub min_da_gas_price: u64,
/// The maximum percentage that the DA portion of the gas price can change in a single block
/// Using `u16` because it can go above 100% and possibly over 255%
pub max_da_gas_price_change_percent: u16,
/// The cumulative reward from the DA portion of the gas price
pub total_da_rewards_excess: u128,
/// The height of the last L2 block recorded on the DA chain
pub da_recorded_block_height: u32,
/// The cumulative cost of recording L2 blocks on the DA chain as of the last recorded block
pub latest_known_total_da_cost_excess: u128,
/// The predicted cost of recording L2 blocks on the DA chain as of the last L2 block
/// (This value is added on top of the `latest_known_total_da_cost` if the L2 height is higher)
pub projected_total_da_cost: u128,
/// The P component of the PID control for the DA gas price
pub da_p_component: i64,
/// The D component of the PID control for the DA gas price
pub da_d_component: i64,
/// The last profit
pub last_profit: i128,
/// The profit before last
pub second_to_last_profit: i128,
/// The latest known cost per byte for recording blocks on the DA chain
pub latest_da_cost_per_byte: u128,
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @MitchTurner, if you can describe which ones we need and which ones are just being used/mutated internally by the AlgorithmUpdater please

Copy link
Member

@MitchTurner MitchTurner Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /// Same as with V0, but we need to multiply it by the `gas_price_factor`. A constructor would help a lot here :)
    pub new_scaled_exec_price: u64,
    /// Same as with V0 (this isn't scaled, I double checked.
    pub min_exec_gas_price: u64,
    /// Same as V0
    pub exec_gas_price_change_percent: u16,
    /// Should be confirmed with metadata sync
    pub l2_block_height: u32,
    /// Same as V0
    pub l2_block_fullness_threshold_percent: ClampedPercentage,
    /// Should be defined in config. Should be multiplied by `gas_price_factor`. Again, constructor would be good.
    pub new_scaled_da_gas_price: u64,
    /// `100` should be good and we can hardcode it if we want.
    pub gas_price_factor: NonZeroU64,
    /// Should be set with config
    pub min_da_gas_price: u64,
    /// Should be set with config
    pub max_da_gas_price_change_percent: u16,
    /// Zero on start (saved in Metadata)
    pub total_da_rewards_excess: u128,
    /// Currently the correct value is required here on startup, i.e. we should know what we expect next from the committer and do the block before that. BUT I think we should allow it to start with None. (saved in Metadata)
    pub da_recorded_block_height: u32,
    /// Zero on start (saved in Metadata)
    pub latest_known_total_da_cost_excess: u128,
    /// Zero on start (saved in Metadata)
    pub projected_total_da_cost: u128,
    /// Set with Config
    pub da_p_component: i64,
    /// Set with Config
    pub da_d_component: i64,
    /// Zero on start (saved in Metadata)
    pub last_profit: i128,
    /// Zero on start (saved in Metadata)
    pub second_to_last_profit: i128,
    /// Zero on start (saved in Metadata)
    pub latest_da_cost_per_byte: u128,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super useful, making the required changes!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lmk if bcb1fd3 makes sense, then i will open the PR for review from others :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that I put (saved in Metadata) on a few of them, but there are others that I missed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the action here? should I change the metadata?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Missed this. I just updated.

@rymnc
Copy link
Member Author

rymnc commented Oct 4, 2024

I have the rest of the code for GasPriceServiceV1, getting them out in chunks though

@rymnc rymnc force-pushed the chore/gas-price-service-v1-metadata branch 3 times, most recently from bcb1fd3 to cfb7b1b Compare October 7, 2024 05:30
@rymnc rymnc force-pushed the chore/gas-price-service-v1-metadata branch from cfb7b1b to 298de5f Compare October 7, 2024 05:33
@MitchTurner MitchTurner marked this pull request as ready for review October 24, 2024 20:04
@MitchTurner
Copy link
Member

So. I wanted to remove the unneeded fields from the metadatas, this let me to modifying how the tests work... which led me to fixing some of the tests. I don't know if we want to keep that in this PR.

Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me. There are a few dangling todos that need to be addressed. Beyond that I just have a few questions and suggestions.

Comment on lines 68 to 69
// TODO: we need to alter fuel-core configuration to include versioned config, after which
// we can directly pass it into the constructor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do it now or create a follow-up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing the TODO. We need to decide if we are going to specify like that or just switch it to the new version and never support the old version. We're tracking the work regardless.

pub starting_gas_price: u64,
pub gas_price_change_percent: u64,
pub gas_price_threshold_percent: u64,
pub enum VersionSpecificConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd prefer the old name here GasPriceServiceConfig. The fact that it's versioned is clear enough given the V0 and V1 variants, and any code which doesn't match on the version variants shouldn't have to care if it's versioned or not.

Suggested change
pub enum VersionSpecificConfig {
pub enum GasPriceServiceConfig

Self::V1(metadata)
}

/// Extract V0MetadataInitializer if it is of V0 version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's V0MetadataInitializer?

@@ -91,27 +116,28 @@ impl MetadataStorage for ErroringMetadata {
}
}

fn arb_config() -> V0AlgorithmConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: While we already use the arb abbreviation for the arb_metadata(), I find it easier to read if we spell out the full word:

Suggested change
fn arb_config() -> V0AlgorithmConfig {
fn arbitrary_config() -> V0AlgorithmConfig {

Comment on lines 80 to 82
pub struct GasPriceServiceConfig {
version_specific_config: VersionSpecificConfig,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of wrapping VersionSpecificCoinfig here as opposed to just having a single enum?

pub enum GasPriceServiceConfig {
    V0(...)
    V1(...)
}

Comment on lines +57 to +59
pub fn new_v1(metadata: V1AlgorithmConfig) -> Self {
Self::V1(metadata)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd complement these constructors with with From<VXAlgorithmConfig> implementations.

// GasPriceData + Modifiable + KeyValueInspect<Column = GasPriceColumn>
impl GasPriceData for FakeGasPriceDb {
fn latest_height(&self) -> Option<BlockHeight> {
todo!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangling todo. Shuld we remove this function or when is it to be implemented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine. It just doesn't get called in the scope of any of these tests, but we're still required to pass something that implements that trait.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change to unimplemented if that's better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah then unimplemented conveys the intention better.

Copy link
Contributor

@AurelienFT AurelienFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice first step towards new gas price 🚀 WP. LGTM.

Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating! 🙏

@MitchTurner MitchTurner merged commit 7605a2a into master Oct 30, 2024
38 checks passed
@MitchTurner MitchTurner deleted the chore/gas-price-service-v1-metadata branch October 30, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore(gas_price_service): define migration logic for metadata from v0 to v1
4 participants